package com.sixth.volunteerservicesystem.Controller.DonationController.backDonation;

import com.sixth.volunteerservicesystem.Dao.DonationRepository;
import com.sixth.volunteerservicesystem.domain.DonationProjects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author Steve Jobs
 * @create 2021-01-11 16:24
 */
@Controller
public class AddDonation {

    @Autowired
    DonationRepository donationRepository;

    @RequestMapping("/addDonation")
    public String addDonation(){

        return "backstageDonation/addDonation";
    }


    @PostMapping("/addDonationBack")
    public String addDonationBack(@RequestParam("title") String title,
                                  @RequestParam("content") String content,
                                  @RequestParam("process") String process,
                                  @RequestParam("src") String src
                                  ){

        src = "/donationImg/" + src;

        DonationProjects donationProjects = new DonationProjects();
        donationProjects.setProductTitle(title);
        donationProjects.setContent(content);
        donationProjects.setProgress(process);
        donationProjects.setSrc(src);

        donationRepository.save(donationProjects);

        return "redirect:/backDonationList";
    }

}
